﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAPbobsCOM;
using System.Reflection;
using System.Runtime.Serialization;

namespace CompanySyncProject
{
    public class DIItem : BaseRun
    {
        public DIItem(Company co, System.IO.StreamWriter lo)
            : base(co, lo)
        {

        }

        public override void Run()
        {
            oCompany.XmlExportType = BoXmlExportTypes.xet_ExportImportMode;

            SAPbobsCOM.Items oitem = oCompany.GetBusinessObject(BoObjectTypes.oItems);
            oitem.ItemCode = "addedbyDI001";
            oitem.ItemName = "addedbyDI0011";
            System.Console.WriteLine("before normal add");
            oitem.Add();
            System.Console.WriteLine("after normal add");
            string ret = oCompany.GetLastErrorDescription();
            System.Console.WriteLine(ret);

            SAPbobsCOM.Items oitem2 = oCompany.GetBusinessObjectFromXML(@"itemaddtestforhiwico.txt", 0);
            System.Console.WriteLine("before xml add");
            oitem2.Add();
            System.Console.WriteLine("after xml add");
            ret = oCompany.GetLastErrorDescription();
            System.Console.WriteLine(ret);

            //SAPbobsCOM.BusinessPartners obp = oCompany.GetBusinessObject(BoObjectTypes.oBusinessPartners);
            //obp.GetByKey("VTWPLDS");
            
            //obp.Addresses.SetCurrentLine(0);
            //obp.Addresses.ZipCode = "33333";
            //string block = obp.Addresses.Block;
            //obp.Browser.ReadXml(@"..\..\test\bpexport.xml", 0);
            //int ret = obp.Update();

//             SAPbobsCOM.StockTransfer ost = oCompany.GetBusinessObject(BoObjectTypes.oStockTransfer);
//             ost.FromWarehouse = "01";
//             ost.Lines.ItemCode = "test";
//             ost.Lines.Quantity = 5;
//             ost.Lines.WarehouseCode = "02";
// 
//             ost.Add();

            //obp.SaveXML(@"..\..\test\bpexport.xml");
            /*SAPbobsCOM.Documents order = oCompany.GetBusinessObject(BoObjectTypes.oPurchaseOrders);
            order.CardCode = "abc";
            order.DocDueDate = DateTime.Now;
            order.Lines.ItemCode = "sss";
            order.Lines.Quantity = 32;
            order.SaveXML(@"..\..\test\output.xml");
            */
            
            //add part

           

//             SAPbobsCOM.Items item = oCompany.GetBusinessObjectFromXML(@"..\..\test\itemadd.txt", 0);
//             string itemcode = item.ItemCode;
//             item.PriceList.SetCurrentLine(1);
//             double price = item.PriceList.Price;
//             item.Add();
// 
// 
//             SAPbobsCOM.Items item2 = oCompany.GetBusinessObject(BoObjectTypes.oItems);
//             item2.GetByKey("myitem40");
//             item2.SaveXML(@"..\..\test\itemexport.txt");
            //order.Browser.ReadXml(@"..\..\test\import3.txt", 0);
            //order.Update();
            

            /*
            SAPbobsCOM.Documents order = oCompany.GetBusinessObject(BoObjectTypes.oPurchaseOrders);
            order.GetByKey(4);
            order.UpdateFromXML(@"..\..\test\import3.txt");
            */

            //savexml
            /*
            SAPbobsCOM.Documents order = oCompany.GetBusinessObject(BoObjectTypes.oPurchaseOrders);
            order.GetByKey(6);
            order.SaveXML(@"..\..\test\output2.xml");
            */

//             SAPbobsCOM.StockTransfer ost = oCompany.GetBusinessObjectFromXML(@"..\..\test\bpexport.xml", 0);
//             ost.Add();
            //SAPbobsCOM.StockTransfer ost = oCompany.GetBusinessObject(BoObjectTypes.oStockTransfer);
            //ost.GetByKey(3);
            //ost.SaveXML(@"..\..\test\stocktransf.xml");
            /*
            ApprovalRequestsService approvalSrv = oCompany.GetCompanyService().GetBusinessService(ServiceTypes.ApprovalRequestsService) as ApprovalRequestsService; 
            ApprovalRequestParams oParams = approvalSrv.GetDataInterface(ApprovalRequestsServiceDataInterfaces.arsApprovalRequestParams) as ApprovalRequestParams;
            oParams.Code = 2457; 
            ApprovalRequest oData = approvalSrv.GetApprovalRequest(oParams);
            oData.ApprovalRequestDecisions.Add();
            oData.ApprovalRequestDecisions.Item(0).ApproverUserName = "test";
            oData.ApprovalRequestDecisions.Item(0).ApproverPassword = "1111";
            oData.ApprovalRequestDecisions.Item(0).Status = BoApprovalRequestDecisionEnum.ardApproved;
            oData.ApprovalRequestDecisions.Item(0).Remarks = "ok";
            approvalSrv.UpdateRequest(oData);
            */

            /*
            SAPbobsCOM.BusinessPartners obp = oCompany.GetBusinessObject(BoObjectTypes.oBusinessPartners);
            obp.GetByKey("VTWXTKJ");
            //obp.ValidFrom = new System.DateTime(2013, 09, 18);
            obp.Browser.ReadXml(@"..\..\test\import2.txt", 0);
            obp.Update();
            */
            /*
            SAPbobsCOM.Documents order = oCompany.GetBusinessObject(BoObjectTypes.oDrafts);
            order.GetByKey(1572);
            order.SaveDraftToDocument();
            */
            //SAPbobsCOM.Documents ost = oCompany.GetBusinessObjectFromXML(@"..\..\test\import2.txt", 0);
            //ost.Add();
            /*
            SAPbobsCOM.BlanketAgreementsService baservice = oCompany.GetCompanyService().GetBusinessService(ServiceTypes.BlanketAgreementsService);
            SAPbobsCOM.BlanketAgreement baheader = baservice.GetDataInterface(BlanketAgreementsServiceDataInterfaces.basBlanketAgreement);
            baheader.BPCode = "C001";
            baheader.StartDate = DateTime.Now;
            baheader.EndDate = DateTime.Now;
            SAPbobsCOM.BlanketAgreements_ItemsLines balines = baheader.BlanketAgreements_ItemsLines;
            balines.Item(0).ItemNo = "I001";
            balines.Item(0).PlannedQuantity = 10;
            balines.Item(0).UnitPrice = 8;
            balines.Add();
            baheader.Description = "added by DI";
            baservice.AddBlanketAgreement(baheader);
            */
            /*
            SAPbobsCOM.ReportLayoutsService reportService = oCompany.GetCompanyService().GetBusinessService(ServiceTypes.ReportLayoutsService);
            SAPbobsCOM.ReportLayoutPrintParams oparams = reportService.GetDataInterface(ReportLayoutsServiceDataInterfaces.rlsdiReportLayoutPrintParams);
            oparams.DocEntry = 1;
            oparams.LayoutCode = "RDR1";
            reportService.Print(oparams);
            */
            /*
            SAPbobsCOM.IJournalEntries oje = oCompany.GetBusinessObject(BoObjectTypes.oJournalEntries);
            //oje.GetByKey(1);
            //oje.SaveXML(@"..\..\test\jeexport2.txt");
            oje.Lines.AccountCode = "100102";
            oje.Lines.FCDebit = 100;
            oje.Lines.FCCurrency = "USD";
            oje.Lines.Debit = 200;
            oje.Lines.Add();
            oje.Lines.SetCurrentLine(1);
            oje.Lines.AccountCode = "100202";
            oje.Lines.FCCredit = 100;
            oje.Lines.Credit = 200;
            oje.Lines.FCCurrency = "USD";
            oje.Add();

            string errMsg = oCompany.GetLastErrorDescription();
            int errcode = oCompany.GetLastErrorCode();
             */
        }
    }
}
